import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/User/Login'
Vue.use(VueRouter)

const routes = [
  {
    path: '/user/login',
    name: 'Login',
    component: Login
  },
]

const routerOptions = {
  mode: 'history',
  base: process.env.BASE_URL,
  routes: routes
}

const router = new VueRouter(routerOptions)

// 解决重复选择菜单路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

//解决退登之后重新登录路由重复的问题
router.$addRoutes = (params) => {
  router.matcher = new VueRouter(routerOptions).matcher;
  router.addRoutes(params)
}

export default router